package 剑指offer;

import org.junit.jupiter.api.Test;

public class 第一个只出现一次的字符 {
    //字典查找
    public char firstUniqChar(String s) {
        if (s.equals(" "))
            return ' ';
        int[] target = new int[26];
        for (int i = 0; i < s.length(); i++) {
            target[s.charAt(i)-'a']++;
        }
        for (int i = 0; i < s.length(); i++) {
            if (target[s.charAt(i)-'a']==1)
                return s.charAt(i);
        }
        return ' ';
    }
    @Test
    public void test(){
        System.out.println(firstUniqChar("leetcode"));
    }
}
